//
//  MSLogInCell.m
//  MS
//
//  Created by Yuan on 13-3-26.
//  Copyright (c) 2013年 He Yuan. All rights reserved.
//

#import "MSLogInCell.h"

@implementation MSLogInCell
@synthesize txtField;
@synthesize imageName;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        txtField = [[UITextField alloc]initWithFrame:CGRectMake(52, 0, 235,50)];
        txtField.backgroundColor = [UIColor clearColor];
        txtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        txtField.tag = 1;
        txtField.font = FONT_NORMAL;
        txtField.delegate = self;
        [self addSubview:txtField];
        
        self.textLabel.font = FONT_NORMAL;
                
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        imageView.tag = 2;
        [imageView setImage:[UIImage imageNamed:@"signup_logo"]];
        self.accessoryView = imageView;
    }
    return self;
}


-(void)resignFirstResponder
{
    [txtField resignFirstResponder];
}

-(void)setImageName:(NSString *)img
{
    imageName = img;
    if (imageName) {
        self.imageView.image = [UIImage imageNamed:[imageName stringByAppendingString:@"_normal"]];
    }
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    self.imageView.image = [UIImage imageNamed:[imageName stringByAppendingString:@"_normal"]];    
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    self.imageView.image = [UIImage imageNamed:[imageName stringByAppendingString:@"_highlighted"]];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    [self setImageStated:selected];
    // Configure the view for the selected state
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
    [super setHighlighted:highlighted animated:animated];
    [self setImageStated:highlighted];
}

-(void)setImageStated:(BOOL)selected{
    
    if (selected)
    {
        self.imageView.image = [UIImage imageNamed:[imageName stringByAppendingString:@"_highlighted"]];
    }else
    {
        self.imageView.image = [UIImage imageNamed:[imageName stringByAppendingString:@"_normal"]];
    }
}


@end
